package com.anjho.pojo;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "reserve")
@NamedQueries(value = {
		@NamedQuery(name = "Reserve.getReserveList", query = "SELECT r FROM Reserve r"),
		@NamedQuery(name = "Reserve.getReserveListByClient", query = "SELECT r FROM Reserve r WHERE r.client = :client")
})
public class Reserve implements Serializable {

	private static final long serialVersionUID = 7972494055377734791L;

	@Id
	@Column(name="recode")
	@OneToMany(mappedBy="reserve")
	@GeneratedValue(strategy=GenerationType.SEQUENCE)
	private long recode;
	
	@Column(name="barcode", nullable=false, length=23)
	private String barcode;
	
	@ManyToOne
	@JoinColumn(name = "clcode", nullable = false)
	private Client client;
	
	public Reserve() {
		this.recode = 0;
		this.barcode = "";
		this.client = new Client();
	}

	public long getRecode() {
		return recode;
	}

	public String getBarcode() {
		return barcode;
	}

	public Client getClient() {
		return client;
	}

	public void setRecode(int recode) {
		this.recode = recode;
	}

	public void setBarcode(String barcode) {
		this.barcode = barcode;
	}

	public void setClient(Client client) {
		this.client = client;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (recode ^ (recode >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Reserve other = (Reserve) obj;
		if (recode != other.recode)
			return false;
		return true;
	}

}
